home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / lib / memory / free.c < prev    next >
C/C++ Source or Header  |  1997-09-09  |  640b  |  40 lines

  1.  
  2. /*
  3.  *  FREE.C
  4.  *
  5.  *    (c)Copyright 1992-1997 Obvious Implementations Corp.  Redistribution and
  6.  *    use is allowed under the terms of the DICE-LICENSE FILE,
  7.  *    DICE-LICENSE.TXT.
  8.  */
  9.  
  10. #include <exec/types.h>
  11. #include <exec/memory.h>
  12. #include <clib/exec_protos.h>
  13. #include <stdlib.h>
  14.  
  15. extern long *__MemList;
  16.  
  17. void
  18. free(ptr)
  19. void *ptr;
  20. {
  21.     long **scan = &__MemList;
  22.     long *item;
  23.  
  24.     if (ptr == NULL)
  25.     return;
  26.  
  27.     ptr = (void *)((long *)ptr - 2);
  28.  
  29.     while (item = *scan) {
  30.     if (item == (long *)ptr) {
  31.         *scan = *(long **)item;
  32.         FreeMem(ptr, ((long *)ptr)[1]);
  33.         return;
  34.     }
  35.     scan = (long **)item;
  36.     }
  37.     Wait(0);
  38. }
  39.  
  40.